﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       Shpm.App.Master.Dao.MstEmployeeDao
 * 类型：       人员信息画面 数据库操作层
 * 功能说明：   对人员信息基本表做追加更新删除操作
 * 作者：       章 昕
 * 创建日期：   2007/07/16
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using Shpm.System.Db;
using Shpm.App.Commons.Db.Beans.Master;

/// <summary>
/// Summary description for MstRecruitDao
/// </summary>
namespace Shpm.App.Master.Dao
{
    public class MstRecruitDao : ShpmBaseDao
    {
        public MstRecruitDao()
        {

        }

        // 画面数据字典 中列表项 内容
        public const string FIND_BY_CATALOG = "CommonDictionary.FindByCatalog";
        // insert recruit
        public const string INSERT_EMPLOYEE = "MstRecruit.InsertEmployee";
        // delete recruit
        public const string DELETE_EMPLOYEE = "MstRecruit.DeleteEmployee";
        // insert IdentityCertificate   
        public const string INSERT_IDENTITY_CERTIFICATE = "MstRecruit.InsertIdentityCertificate";
        // insert ProfessionCertificate
        public const string INSERT_PROFESSION_CERTIFICATE = "MstRecruit.InsertProfessionCertificate";
        // insert WishPosition
        public const string INSERT_WISH_POSITION = "MstRecruit.InsertWishPosition";
        // insert LeadVerify
        public const string INSERT_LEAD_VERIFY = "MstRecruit.InsertLeadVerify";
        // insert HouseKeeping
        public const string INSERT_HOUSE_KEEPING = "MstRecruit.InsertHouseKeeping";

        // get catalog
        public IList FindByCatalog(CommonDictionaryBean paramBean)
        {
            return base.QueryForList(FIND_BY_CATALOG, paramBean);
        }


        // insert Employee
        // parameters
        // paramBean        -- MstRecruitBean data bean
        // lstCertifiy      -- 提交证明lst
        // lstQalify1       -- 家政资格证书lst
        // lstQalify2       -- 护理证lst
        // lstWishWork      -- 个人志愿lst
        // lstHouseKeeping  -- 家政服务史
        public int InsertEmployeeData(MstRecruitBean paramBean,
            IList lstCertifiy, IList lstQalify1, IList lstQalify2, IList lstWishWork,
            LeadVerifyBean leadVerify, IList lstHouseKeeping)
        {
            try
            {   
                           
                base.BeginTransaction();

                // 1 insert employee
                this.InsertEmployee(paramBean);

                // 2 insert identity certificate 
                foreach (string recordId in lstCertifiy)
                {
                    IdentityCertificateBean beanIdentityC = new IdentityCertificateBean();
                    beanIdentityC.EmpCode = paramBean.EmpCode;
                    beanIdentityC.DictNo = int.Parse(recordId);
                    beanIdentityC.UserId = paramBean.UserId;
                    beanIdentityC.NewDate = paramBean.NewDate;
                    this.InsertIdentityC(beanIdentityC);
                }

                // 3 insert profession certificate
                foreach (string recordId in lstQalify1)
                {
                    if (!recordId.Equals("0"))
                    {
                        ProfessionCertificateBean beanProfessionC = new ProfessionCertificateBean();
                        beanProfessionC.EmpCode = paramBean.EmpCode;
                        beanProfessionC.DictNo = int.Parse(recordId);
                        beanProfessionC.UserId = paramBean.UserId;
                        beanProfessionC.NewDate = paramBean.NewDate;
                        this.InsertProfessionC(beanProfessionC);
                    }
                }                
                foreach (string recordId in lstQalify2)
                {
                    if (!recordId.Equals("0"))
                    {
                        ProfessionCertificateBean beanProfessionC = new ProfessionCertificateBean();
                        beanProfessionC.EmpCode = paramBean.EmpCode;
                        beanProfessionC.DictNo = int.Parse(recordId);
                        beanProfessionC.UserId = paramBean.UserId;
                        beanProfessionC.NewDate = paramBean.NewDate;
                        this.InsertProfessionC(beanProfessionC);
                    }
                }

                
                // 4 insert wish position 
                foreach (string recordId in lstWishWork)
                {
                    WishPositionBean beanWishP = new WishPositionBean();
                    beanWishP.EmpCode = paramBean.EmpCode;
                    beanWishP.DictNo = int.Parse(recordId);
                    beanWishP.UserId = paramBean.UserId;
                    beanWishP.NewDate = paramBean.NewDate;
                    this.InsertWishP(beanWishP);
                }

                // 5 insert lead verify
                this.InsertLeadV(leadVerify);

                // 6 insert house keeping
                foreach (HousekeepingBean beanHouseK in lstHouseKeeping)
                {
                    this.InsertHouseK(beanHouseK);
                }

                base.CommitTransaction();

                return 0;
            }
            catch (DataAccessException e)
            {
                Console.WriteLine("********** Exec  sql error! **********");
                Console.WriteLine(e.InnerException);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                base.RollBackTransaction();
                return 1;
            }
            finally 
            {
                
            }
        }

        // insert data into Employee Table
        public Object InsertEmployee(MstRecruitBean paramBean) 
        {
            return base.Insert(INSERT_EMPLOYEE, paramBean);
        }

        // delete data from Employee Table
        public int DeleteEmployee(MstRecruitBean paramBean) 
        {
            return base.Delete(DELETE_EMPLOYEE, paramBean);
        }

        // insert data into IdentityCertificate Table
        public Object InsertIdentityC(IdentityCertificateBean paramBean)
        {
            return base.Insert(INSERT_IDENTITY_CERTIFICATE, paramBean);
        }

        // insert data into ProfessionCertificate Table
        public Object InsertProfessionC(ProfessionCertificateBean paramBean) 
        {
            return base.Insert(INSERT_PROFESSION_CERTIFICATE, paramBean);
        }

        // insert data into WishPosition Table
        public Object InsertWishP(WishPositionBean paramBean)
        {
            return base.Insert(INSERT_WISH_POSITION, paramBean);
        }

        // insert data into LeadVerify Table
        public Object InsertLeadV(LeadVerifyBean paramBean) 
        {
            return base.Insert(INSERT_LEAD_VERIFY, paramBean);
        }

        // insert data into HouseKeeping Table
        public Object InsertHouseK(HousekeepingBean paramBean)
        {
            return base.Insert(INSERT_HOUSE_KEEPING, paramBean);
        }
    }
}
